#!/bin/bash
ver=$1

if [[ -z "$ver" ]]; then
	ver="stable"
fi


cd /opt/;
svn co https://192.168.130.6:8443/svn/winit2.0/frameworks/tags/ucloud-agent-$ver;

killall -9 python;
rm -rf /opt/beetle-agent;
rm -rf /opt/ucloud-agent;

mv /opt/ucloud-agent* /opt/ucloud-agent;

beetle_src='beetle'
ucloud_target='ucloud'


r_file='/usr/sbin/r'
rt_file='/usr/sbin/rt'
ta_file='/usr/sbin/ta'

sed -i "s/$beetle_src/$ucloud_target/g" $r_file;
sed -i "s/$beetle_src/$ucloud_target/g" $rt_file;

# Not yet.
# sed -i "s/$beetle_src/$ucloud_target/g" $ta_file;

chmod  775 -R /opt/ucloud-agent/shell/*;